// WARNING: This file has been generated. Any manual changes must be made within preserved regions or they will be lost.

//===============================================================================
//
// DatesTests
//
// PURPOSE: 
// Tests the functionality of Dates.
//
// NOTES: 
// 
//
//===============================================================================
//
// Copyright (C) 2003 Wallis Software Solutions
// All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED 'AS IS' WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR
// FITNESS FOR A PARTICULAR PURPOSE.
//
//===============================================================================

using System;
using System.Data.SqlTypes;
using System.Globalization;
using NUnit.Framework;

namespace Agile.Common.Tests
{
    /// <summary>
    /// Tests the functionality of Dates.
    /// </summary>
    [TestFixture]
    public class DatesTests
    {
        /// <summary>
        /// Verifies invalid strings return false
        ///		- Check &nlbr; returns false
        /// </summary>
        [Test]
        public void InvalidStringTests()
        {
            // Check &nlbr; returns false
            Assert.IsFalse(Dates.IsDate("&nlbr;"), "Check &nlbr; returns false");
        }

        /// <summary>
        /// Test the Between function
        /// - Date below either of the others
        /// - Date on lower bound (first is lower)
        /// - Date on lower bound (second is lower)
        /// - Date on upper bound (first is higher)
        /// - Date on upper bound (second is higher)
        /// - Date above both dates
        /// - Date between bounds (first is lower)
        /// - Date between bounds (second is lower)
        /// </summary>
        [Test]
        public void TestBetween()
        {
            var low = new DateTime(2005, 1, 13, 12, 34, 56);
            var high = new DateTime(2005, 3, 17, 7, 54, 32);

            // Date below either of the others
            Assert.IsFalse(Dates.Between(new DateTime(2004, 3, 5, 6, 7, 8), low, high));

            // Date on lower bound (first is lower)
            Assert.IsTrue(Dates.Between(low, low, high));

            // Date on lower bound (second is lower)
            Assert.IsTrue(Dates.Between(low, high, low));

            // Date on upper bound (first is higher)
            Assert.IsTrue(Dates.Between(high, low, high));

            // Date on upper bound (second is higher)
            Assert.IsTrue(Dates.Between(high, high, low));

            // Date above both dates
            Assert.IsFalse(Dates.Between(new DateTime(2006, 3, 5, 6, 7, 8), low, high));

            // Date between bounds (first is lower)
            Assert.IsTrue(Dates.Between(new DateTime(2005, 2, 25, 0, 0, 0), low, high));

            // Date between bounds (second is lower)
            Assert.IsTrue(Dates.Between(new DateTime(2005, 2, 25, 0, 0, 0), high, low));
        }

        /// <summary>
        /// There are a few formatting functions that make sure dates, numbers
        /// etc all look the same across all the applications
        ///		- check format date (1 Jan 2003) = 1 Jan 2003
        ///		- check format date (11 Jan 2003) = 11 Jan 2003
        ///		- check format sql date (1 jan 2003) = 1 jan 2003
        /// </summary>
        [Test]
        public void TestFormattingFunctions()
        {
            //		- check format date (1 Jan 2003) = 1 Jan 2003
            Assert.IsTrue(Dates.Format(DateTime.Parse("1/jan/2003", CultureInfo.CurrentCulture)) == "1 Jan 2003"
                          , "check format date (1 Jan 2003) = 1 Jan 2003");

            //		- check format date (11 Jan 2003) = 11 Jan 2003
            Assert.IsTrue(Dates.Format(DateTime.Parse("11/jan/2003", CultureInfo.CurrentCulture)) == "11 Jan 2003"
                          , "check format date (11 Jan 2003) = 11 Jan 2003");

            //		- check format sql date (1 jan 2003) = 1 jan 2003
            Assert.IsTrue(Dates.Format(new SqlDateTime(2003, 1, 1)) == "1 Jan 2003"
                          , "check format sql date (1 jan 2003) = 1 jan 2003");
        }

        /// <summary>
        /// Test SameDate
        ///     - check  21/mar/1999 10:00 is same date as 21/mar/1999 11:00
        ///     - check  22/mar/1999 23:59 is different date to 23/mar/1999 0:10
        /// </summary>
        [Test]
        public void TestSameDate()
        {
            //     - check  21/mar/1999 10:00 is same date as 21/mar/1999 11:00
            Assert.IsTrue(Dates.SameDate(DateTime.Parse("21/mar/1999 10:00", CultureInfo.CurrentCulture),
                                         DateTime.Parse("21/mar/1999 11:00", CultureInfo.CurrentCulture)),
                          "Check dates are same");

            //     - check  22/mar/1999 23:59 is different date to 23/mar/1999 0:10
            Assert.IsFalse(Dates.SameDate(DateTime.Parse("22/mar/1999 23:59", CultureInfo.CurrentCulture),
                                          DateTime.Parse("23/mar/1999 0:10", CultureInfo.CurrentCulture)),
                           "check dates are different");
        }

        /// <summary>
        /// Tests the ZeroMilliSeconds function
        /// - Test something with some milliseconds
        /// </summary>
        [Test]
        public void TestZeroMilliseconds()
        {
            // Test something with some milliseconds
            var first = new DateTime(2005, 3, 14, 12, 34, 56, 789);
            var firstZero = new DateTime(2005, 3, 14, 12, 34, 56, 0);
            Assert.IsFalse(first == firstZero, "Check the are not equal");
            Assert.AreEqual(firstZero, Dates.ZeroMilliseconds(first), "Check the ms have been zeroed");
        }
    }
}